package com.mzj.saas.mservice.backlog.controller;

import com.mzj.saas.commons.ApiData;
import com.mzj.saas.commons.ResultBean;
import com.mzj.saas.mservice.backlog.service.BacklogService;
import com.mzj.saas.mservice.backlog.vo.*;
import com.mzj.saas.mservice.house.vo.HouseVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 待办事项接口
 */
@Controller
@RequestMapping("/backlog")
@Api(tags = "消息（待办事项）")
public class BacklogController {

    @Autowired
    private BacklogService backlogService;

    /**
     * 待办事项列表
     *
     * @param accessToken
     * @param status
     * @param pageNumber
     * @param pageSize
     * @return
     */
    @GetMapping("/backlogList")
    @ResponseBody
    @ApiOperation("消息列表（待办事项列表）")
    public ResultBean<BacklogItemApiData<BacklogListVO>> backlogList(@RequestHeader String accessToken,
                                                                     @RequestParam(value = "status", required = true)
                                                                     @ApiParam(name = "status",value = "状态：0全部，1待我处理的，2我发起的，3我参与的，4已完成的") Integer status,
                                                                     @RequestParam(defaultValue = "0")
                                                                     @ApiParam(name = "pageNumber",value = "当前页") Integer pageNumber,
                                                                     @RequestParam(defaultValue = "5")
                                                                     @ApiParam(name = "pageSize",value = "每页条数") Integer pageSize) {
        return backlogService.backlogList(accessToken, status, pageNumber, pageSize);
    }

    /**
     * 待办事项列表v2
     *
     * @param accessToken
     * @param status
     * @param pageNumber
     * @param pageSize
     * @return
     */
    @GetMapping("/backlogHouseList")
    @ResponseBody
    @ApiOperation("消息列表（待办事项列表）V2")
    public ResultBean<BacklogItemApiData<BacklogListVO>> backlogHouseList(@RequestHeader String accessToken,
                                                                     @RequestParam(value = "status", required = true)
                                                                     @ApiParam(name = "status",value = "状态：0全部，1待我处理的，2我发起的，3我参与的，4已完成的") Integer status,
                                                                     @RequestParam(defaultValue = "0")
                                                                     @ApiParam(name = "pageNumber",value = "当前页") Integer pageNumber,
                                                                     @RequestParam(defaultValue = "5")
                                                                     @ApiParam(name = "pageSize",value = "每页条数") Integer pageSize,
                                                                     @RequestParam(value = "houseId", required = false)
                                                                     @ApiParam(name = "houseId",value = "房屋Id") String houseId) {
        return backlogService.backlogHouseList(accessToken, status, pageNumber, pageSize, houseId,false);
    }

    @GetMapping("/apartment/backlogHouseList")
    @ResponseBody
    @ApiOperation("消息列表（待办事项列表）V2（公寓小程序消息通知！！）")
    public ResultBean<BacklogItemApiData<BacklogListVO>> backlogHouseApartmentList(@RequestHeader String accessToken,
                                                                          @RequestParam(value = "status", required = true)
                                                                          @ApiParam(name = "status",value = "状态：0全部，1待我处理的，2我发起的，3我参与的，4已完成的") Integer status,
                                                                          @RequestParam(defaultValue = "0")
                                                                          @ApiParam(name = "pageNumber",value = "当前页") Integer pageNumber,
                                                                          @RequestParam(defaultValue = "5")
                                                                          @ApiParam(name = "pageSize",value = "每页条数") Integer pageSize,
                                                                          @RequestParam(value = "houseId", required = false)
                                                                          @ApiParam(name = "houseId",value = "房屋Id") String houseId) {
        return backlogService.backlogHouseList(accessToken, status, pageNumber, pageSize, houseId,true);
    }

    /**
     * 公租房绑定详情
     *
     * @param accessToken
     * @param id
     * @return
     */
    @GetMapping("/houseBindDetail")
    @ResponseBody
    public ResultBean<HouseBindDetailVO> houseBindDetail(@RequestHeader String accessToken,
                                                         @RequestParam(value = "id") Long id) {
        return backlogService.houseBindDetail(accessToken, id);
    }

    /**
     * 审批公租房绑定,实现公租房的审批操作
     *
     * @param accessToken 权限鉴定
     * @param id           待办事项id
     * @param type        1通过 2不通过
     * @return
     */
    @GetMapping("/approveHouseBind")
    @ResponseBody
    public ResultBean<Object> approveHouseBind(@RequestHeader String accessToken,
                                               @RequestParam(value = "id") Long id,
                                               @RequestParam(value = "type") Integer type) {
        return backlogService.approveHouseBind(accessToken, id, type);
    }

    /**
     * 查看绑定资料
     *
     * @param accessToken
     * @param id
     * @param pageNumber
     * @param pageSize
     * @return
     */
    @GetMapping("/findBindData")
    @ResponseBody
    public ResultBean<ApiData<HouseVO>> findBindData(@RequestHeader String accessToken,
                                                     @RequestParam(value = "id") Long id,
                                                     @RequestParam(defaultValue = "0") Integer pageNumber,
                                                     @RequestParam(defaultValue = "5") Integer pageSize) {
        return backlogService.findBindData(accessToken, id, pageNumber, pageSize);
    }

    /**
     * 待办事项app支付
     *
     * @param accessToken
     * @return
     */
    @PostMapping("/payment")
    @ResponseBody
    public ResultBean<Map<String, Object>> payment(@RequestHeader String accessToken, @RequestBody BacklogPaymentVO vo) {
        return backlogService.payment(accessToken, vo);
    }

    /**
     * 个人锁申请详情
     *
     * @param accessToken
     * @param id
     * @return
     */
    @GetMapping("/personLockDetail")
    @ResponseBody
    public ResultBean<PersonLockDetailVO> personLockDetail(@RequestHeader String accessToken,
                                                           @RequestParam(value = "id") Long id) {
        return backlogService.personLockDetail(accessToken, id);
    }

    /**
     * 个人锁申请确认
     *
     * @param accessToken
     * @param id
     * @param type        1通过 2不通过
     * @param reason
     * @return
     */
    @GetMapping("/personLockConfirm")
    @ResponseBody
    public ResultBean<Object> personLockConfirm(@RequestHeader String accessToken,
                                                @RequestParam(value = "id") Long id,
                                                @RequestParam(value = "type") Integer type,
                                                @RequestParam(value = "reason", required = false) String reason) {
        return backlogService.personLockConfirm(accessToken, id, type, reason);
    }

    /**
     * (合同)租金/押金参数
     *
     * @param accessToken
     * @param id
     * @return
     */
    @GetMapping("/findContractBill")
    @ResponseBody
    public ResultBean<ContractBillParamVO> findContractBill(@RequestHeader String accessToken,
                                                            @RequestParam(value = "id") Long id) {
        return backlogService.findContractBill(accessToken, id);
    }

    /**
     * 合同待确认参数
     *
     * @param accessToken
     * @param id
     * @return
     */
    @GetMapping("/findContractConfirm")
    @ResponseBody
    public ResultBean<Object> findContractConfirm(@RequestHeader String accessToken,
                                                  @RequestParam(value = "id") Long id) {
        return backlogService.findContractConfirm(accessToken, id);
    }


    /**
     * 冻结/解冻详情
     *
     * @param accessToken
     * @param id
     * @return
     */
    @GetMapping("/backlogCardInfo")
    @ResponseBody
    public ResultBean<Object> backlogCardInfo(@RequestHeader String accessToken,
                                                  @RequestParam(value = "id") Long id) {
        return backlogService.backlogCardInfo(accessToken, id);
    }


    /**
     * 房屋动态详情、消息状态更改（已读）
     * @param accessToken
     * @param id
     * @return
     */
    @GetMapping("/houseInfo")
    @ResponseBody
    @ApiOperation("房屋动态详情、消息状态更改（已读）")
    public ResultBean<Object> houseInfo(@RequestHeader String accessToken,
                                              @RequestParam(value = "id")
                                              @ApiParam(name = "id",value = "待办事项id") Long id) {
        return backlogService.houseInfo(accessToken, id);
    }

    /**
     * 删除房屋动态消息
     * @param accessToken
     * @param idList
     * @return
     */
    @DeleteMapping("/deleteHouseInfo")
    @ResponseBody
    @ApiOperation("删除房屋动态消息")
    public ResultBean<Object> deleteHouseInfo(@RequestHeader String accessToken,
                                              @RequestBody
                                        @ApiParam(name = "idList",value = "待办事项idList") List<Long> idList) {
        return backlogService.deleteHouseInfo(accessToken, idList);
    }

    /**
     * 根据用户查询未做人脸授权的房子，并对其进行消息推送
     * @param accessToken
     * @return
     */
    @GetMapping("/authFace")
    @ResponseBody
    public ResultBean<Object> authFace(@RequestHeader String accessToken ) {
        return backlogService.authFace(accessToken);
    }
}
